package controllers;

import play.*;
import play.mvc.*;
import play.mvc.Http.*;

import models.*;

public class StaffSecured extends Secured {

    @Override
    public String getUsername(Context ctx) {
		String loggedUser = super.getUsername(ctx);

		String uuid = ctx.session().get("uuid");
		Integer role = LogSession.getRoleFromUUID(uuid);

		if (role == null || (role!= 1 && role != 2))
			return null;

        return loggedUser;
    }

	@Override
    public Result onUnauthorized(Context ctx) {
		ctx.flash().put("refuri",ctx.request().uri());
		ctx.flash().put("error","Illegal action");
        return redirect(routes.Application.login("en"));
    }

}